<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=
    , initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body{
            background: black;
            text-align: center;
        }
        #c1{
            background: #fff;
        }
    </style>
    <script>
        window.onload=function(){
            let oC=document.getElementById('c1');
            let gd=oC.getContext('2d');
            let lastX,lastY;
            oC.onmousedown=function(ev){
                console.log(ev)
                lastX=ev.offsetX;
                lastY=ev.offsetY;
            }
            oC.onmousemove=function(ev){
                // console.log(ev)
            
                if(lastX!=null){
                gd.beginPath();
                let x,y;
                x=ev.offsetX;
                y=ev.offsetY;
                gd.moveTo(lastX,lastY);
                gd.lineTo(x,y);
                lastX=x;
                lastY=y;
                gd.strokeStyle='red';
                gd.stroke();
                }
            }
            oC.onmouseup=function(){
                lastX=null;
                lastY=null;
            }
        }
    </script>
</head>
<body>
    <canvas id="c1" width="800" height="600">
        
    </canvas>
</body>
</html>